package cn.evun.proabslistview;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.ilioili.proabslist.AbsLoadView;
import com.laoxinwen.app.R;

public class LoadView implements AbsLoadView {

    private LinearLayout loadView;
    private ProgressBar pb;
    private TextView tvHint;

    public LoadView(Context context) {
        FrameLayout root = new FrameLayout(context);
        loadView = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.proabslistview_loader, root, false);
        tvHint = (TextView) loadView.findViewById(R.id.load_hint_txt);
        pb = (ProgressBar) loadView.findViewById(R.id.load_progressbar);
    }

    private int dp2px(int dp, Context c) {
        return (int) (c.getResources().getDisplayMetrics().density * dp);
    }

    @Override
    public void onScrollWhileLoadViewVisible(int percentage) {
        if (percentage <= 100) {
            tvHint.setText("上拉可以加载更多");
        } else {
            tvHint.setText("松手开始加载");
        }
        pb.setVisibility(View.GONE);
    }

    @Override
    public void onLoading() {
        tvHint.setText("努力加载中");
        pb.setVisibility(View.VISIBLE);
    }

    @Override
    public void onLoadCompleted() {
        tvHint.setText("加载完毕");
        pb.setVisibility(View.GONE);
    }

    @Override
    public View getLoadView() {
        return loadView;
    }

}
